#!/bin/bash
# --------------------------------------------------
#Author:  LJ
#Email:   admin@attacker.club

#Last Modified: 2018-06-24 18:46:04
#Description:  一键安装常用vsftp
# -------------------------------------------------


Install()
{
  yum remove vsftpd -y && rm /etc/vsftpd/ -rf
  yum install vsftpd -y
}

Set_conf()
{
 sed -i "s/userlist_enable=YES/userlist_deny=NO/" /etc/vsftpd/vsftpd.conf
 # 使user_list​为NO，只允许列表内用户访问
 sed -i  "s/anonymous_enable=YES/anonymous_enable=NO/" /etc/vsftpd/vsftpd.conf
 echo "ftp" >>  /etc/vsftpd/ftpusers
 # 限制匿名账号
 sed -i  "s/#chroot_local_user=YES/chroot_local_user=YES/" /etc/vsftpd/vsftpd.conf
 # 限制在USER家目录

 repo=`df |grep dev |sort -nrk 2|head -1|awk '{print $NF"repo"}'`
 #最大分区做ftp 目录
 mkdir $repo
 groupadd ftpcenter
 useradd   -M -s /sbin/nologin -g ftpcenter  -d $repo  ftpcenter
 echo "ftppass"|passwd --stdin "ftpcenter" #修改密码
}

Run ()
{
  chmod a-w $repo
  service vsftpd restart
  chkconfig vsftpd on

}

Install
Set_conf
Run


echo "++++++++++++++++ Complete the installation　！ +++++++++++++++++"